package aoj.no_1000;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class No_1004 {
	public static void main(String[] args) throws IOException {
		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(input);
		
		String line = reader.readLine();
		while(line != null) {
			int n = Integer.parseInt(line);
			boolean[] primes = getPrimes(n);
			
			int ans = 0;
			for(int i = 1; i <= n; i++) {
				if(primes[i] && primes[n+1-i]) {
					ans++;
				}
			}
			System.out.println(ans);
			
			line = reader.readLine();
		}
	}
	
	public static boolean[] getPrimes(int n) {
		boolean[] numbers = new boolean[n+1];
		for(int i = 0; i < numbers.length; i++)
			numbers[i] = true;
		
		numbers[0] = numbers[1] = false;
		
		for(int i = 0; i < n; i++) {
			if(numbers[i] == false)
				continue;
			for(int j = 2; j <= n/i; j++) {
				numbers[i*j] = false;
			}
		}		
		return numbers;
	}
}
/*
1
4
7
51 
*/
